package com.equipment.management.controller;

import com.alibaba.fastjson.JSON;
import com.equipment.management.entity.QueryInfo;
import com.equipment.management.entity.SensorData;
import com.equipment.management.dao.SensorDataDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class SensorDataController {

    @Autowired
    private SensorDataDao sensorDataDao;

    @RequestMapping("/getalldata")
    public String getAllData(QueryInfo queryInfo){
        // 获取最大列表数和当前编号
        int number = sensorDataDao.getDataCounts("%" + queryInfo.getQuery() + "%");
        int pageStart = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();

        List<SensorData> data = sensorDataDao.getAllData("%" + queryInfo.getQuery() + "%", pageStart, queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("number", number);
        res.put("data", data);
        String res_string = JSON.toJSONString(res);
        return res_string;
    }
}
